package com.orange.shiro.utils;

import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.crypto.hash.SimpleHash;

public class ShiroMD5 {
    public static void main(String[] args) {
        //密码明文
        String password = "123456";

        //使用MD5加密
        Md5Hash md5Hash = new Md5Hash(password);
        System.out.println("MD5加密 = " + md5Hash);

        ///带盐的md5加密,盐就是在密码明文后拼接新字符串,然后再进行加密
        Md5Hash md5Hash2 = new Md5Hash(password, "salt");
        System.out.println("带盐 MD5加密 = " + md5Hash2.toHex());

        //为了保证安全，避免被破解还可以多次迭代加密，保证数据安全
        Md5Hash md5Hash3 = new Md5Hash(password, "salt", 5);
        System.out.println("带盐 MD5 五次加密 = " + md5Hash3.toHex());

        //使用父类实现加密
        SimpleHash simpleHash = new SimpleHash("MD5", password, "salt", 5);
        System.out.println("父类 MD5 带盐五次加密 = " + simpleHash.toHex());

    }
}
